import Vue from "vue";
import VueRouter from "vue-router";
import allRouter from "./allRouters";

// 解决路由重复点击报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "Login",
    component: () =>
      import(/*webpackChunkName:'login'*/ "../views/Login/Login.vue"),
  },
  {
    path: "/home",
    name: "Home",
    component: () =>
      import(/*webpackChunkName:'login'*/ "../views/Home/Home.vue"),
    children: allRouter,
  },
  {
    path: "*",
    component: () => import(/*webpackChunkName:"page404"*/ "../views/Page404"),
  },
  {
    path: "/",
    redirect: "/login",
  },
];

const router = new VueRouter({
  routes,
});

export default router;
